import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
/// @Author: xiaoMaiSui
/// @Date: 2025-1-0 09:22:16
/// @LastEditTime:
class Global {
  /// api
  //static final API api = API();

  /// 屏幕适配
 // static final ScreenAdapter screenAdapter = ScreenAdapter();

  /// 导航栏高度
  static final double top = MediaQuery.of(Global.getCurrentContext()).padding.top;
  /// 获取导航栏高度
  static final double statusH=  MediaQuery.of(Global.getCurrentContext()).padding.top ;
  /// 宽度
  static final double width = MediaQuery.of(Global.getCurrentContext()).size.width;

  /// 高度
  static final double height = MediaQuery.of(Global.getCurrentContext()).size.height;

  /// 加载器
  static Widget loader() {
    return const Center(child: CircularProgressIndicator());
  }

  // 将请求参数，由 Map 类型解析成 query 字符串
  // urlpath?a=1&b=2&c=3
  static parseQuery({Map<String, dynamic>? params}) {
    String target = "";
    if (params != null) {
      int index = 0;
      for (String key in params.keys) {
        final String value = Uri.encodeComponent(params[key].toString());
        if (index == 0) {
          target = "?";
        } else {
          target = target + "\&";
        }
        target += "$key=$value";
        index++;
      }
    }

    return target.toString();
  }

  static success(String msg) {
    return EasyLoading.showSuccess(msg);
  }

  static error(String msg) {
    return EasyLoading.showError(msg);
  }

  static toast(String msg) {
    return EasyLoading.showToast(msg);
  }

  // 导航唯一key
  static final GlobalKey<NavigatorState> navigatorKey = GlobalKey();

  // 当前的构建上下文
  static BuildContext getCurrentContext() => navigatorKey.currentContext!;

/// 翻译函数
// static String t(String key) {
//   return CustomLocalizations.of(getCurrentContext()).t(key);
// }
}
